from google.appengine.ext import db

# Create your models here.
class MarketStatsMail(db.Model):
    sender = db.StringProperty( indexed=False)
    subject = db.StringProperty( indexed=False)
    date = db.StringProperty( indexed=False)
    statsdata = db.ListProperty(long,  indexed=False)
    datasize = db.IntegerProperty(indexed=False)
    added_on = db.DateTimeProperty(auto_now_add=True,  indexed=False)

class MarketStatsAttach(db.Model):
    statsdata = db.TextProperty(indexed=False)

class MarketStats(db.Model):
    typeID = db.IntegerProperty(required=True, indexed=False)
    regionID = db.IntegerProperty(indexed=False)
    solarSystemID = db.IntegerProperty(required=True, indexed=False)
    updated = db.DateTimeProperty(indexed=False)
    ordersSell = db.IntegerProperty(default=0, indexed=False)
    minSellPrice = db.IntegerProperty(default=0, indexed=False)
    maxSellPrice = db.IntegerProperty(default=0, indexed=False)
    averageSellPrice = db.IntegerProperty(default=0, indexed=False)
    medianSellPrice = db.IntegerProperty(default=0, indexed=False)
    volSellRemaining = db.IntegerProperty(default=0,  indexed=False)
    volSellEntered = db.IntegerProperty(default=0,  indexed=False)
    newestSellOrder = db.DateProperty(default=None,  indexed=False)
    oldestSellOrder = db.DateProperty(default=None,  indexed=False)
    ordersBuy = db.IntegerProperty(default=0,  indexed=False)
    minBuyPrice = db.IntegerProperty(default=0,  indexed=False)
    maxBuyPrice = db.IntegerProperty(default=0,  indexed=False)
    averageBuyPrice = db.IntegerProperty(default=0,  indexed=False)
    medianBuyPrice = db.IntegerProperty(default=0,  indexed=False)
    volBuyRemaining = db.IntegerProperty(default=0,  indexed=False)
    volBuyEntered = db.IntegerProperty(default=0,  indexed=False)
    newestBuyOrder = db.DateProperty(default=None,  indexed=False)
    oldestBuyOrder = db.DateProperty(default=None,  indexed=False)
    
    def __str__(self):
        return "MarketStats(%s) : u:%s, t:%06d, s:%09d, sell- o:%09d, mn:%012d, mx:%012d, a:%012d, m:%012d, r:%012d, e:%012d, nw:%s, od:%s, buy- o:%09d, mn:%012d, mx:%012d, a:%012d, m:%012d, r:%012d, e:%012d, nw:%s, od:%s" % (self.key().name(), str(self.updated), self.typeID, self.solarSystemID, self.ordersSell, self.minSellPrice, self.maxSellPrice, self.averageSellPrice, self.medianSellPrice, self.volSellRemaining, self.volSellEntered, str(self.newestSellOrder), str(self.oldestSellOrder), self.ordersBuy, self.minBuyPrice, self.maxBuyPrice, self.averageBuyPrice, self.medianBuyPrice, self.volBuyRemaining, self.volBuyEntered, str(self.newestBuyOrder), str(self.oldestBuyOrder))


class MarketHistory(MarketStats):
    date = db.DateProperty(required=True, indexed=False)

    def __str__(self):
        return "MarketHistory(%s) : u:%s, t:%06d, s:%09d, d:%s, sell- o:%09d, mn:%012d, mx:%012d, a:%012d, m:%012d, r:%012d, e:%012d, nw:%s, od:%s, buy- o:%09d, mn:%012d, mx:%012d, a:%012d, m:%012d, r:%012d, e:%012d, nw:%s, od:%s" % (self.key().name(), str(self.updated), self.typeID, self.solarSystemID, str(self.date), self.ordersSell, self.minSellPrice, self.maxSellPrice, self.averageSellPrice, self.medianSellPrice, self.volSellRemaining, self.volSellEntered, str(self.newestSellOrder), str(self.oldestSellOrder), self.ordersBuy, self.minBuyPrice, self.maxBuyPrice, self.averageBuyPrice, self.medianBuyPrice, self.volBuyRemaining, self.volBuyEntered, str(self.newestBuyOrder), str(self.oldestBuyOrder))


class TmpMarketStats(db.Model):
    typeID = db.IntegerProperty(required=True)
    regionID = db.IntegerProperty(indexed=False)
    solarSystemID = db.IntegerProperty(required=True)
    updated = db.DateTimeProperty()
    ordersSell = db.IntegerProperty(default=0, indexed=False)
    minSellPrice = db.IntegerProperty(default=0, indexed=False)
    maxSellPrice = db.IntegerProperty(default=0, indexed=False)
    averageSellPrice = db.IntegerProperty(default=0, indexed=False)
    medianSellPrice = db.IntegerProperty(default=0, indexed=False)
    volSellRemaining = db.IntegerProperty(default=0,  indexed=False)
    volSellEntered = db.IntegerProperty(default=0,  indexed=False)
    newestSellOrder = db.DateProperty(default=None,  indexed=False)
    oldestSellOrder = db.DateProperty(default=None,  indexed=False)
    ordersBuy = db.IntegerProperty(default=0,  indexed=False)
    minBuyPrice = db.IntegerProperty(default=0,  indexed=False)
    maxBuyPrice = db.IntegerProperty(default=0,  indexed=False)
    averageBuyPrice = db.IntegerProperty(default=0,  indexed=False)
    medianBuyPrice = db.IntegerProperty(default=0,  indexed=False)
    volBuyRemaining = db.IntegerProperty(default=0,  indexed=False)
    volBuyEntered = db.IntegerProperty(default=0,  indexed=False)
    newestBuyOrder = db.DateProperty(default=None,  indexed=False)
    oldestBuyOrder = db.DateProperty(default=None,  indexed=False)

class TmpMarketHistory(db.Model):
    typeID = db.IntegerProperty(required=True)
    regionID = db.IntegerProperty(indexed=False)
    solarSystemID = db.IntegerProperty(required=True)
    updated = db.DateTimeProperty()
    ordersSell = db.IntegerProperty(default=0, indexed=False)
    minSellPrice = db.IntegerProperty(default=0, indexed=False)
    maxSellPrice = db.IntegerProperty(default=0, indexed=False)
    averageSellPrice = db.IntegerProperty(default=0, indexed=False)
    medianSellPrice = db.IntegerProperty(default=0, indexed=False)
    volSellRemaining = db.IntegerProperty(default=0,  indexed=False)
    volSellEntered = db.IntegerProperty(default=0,  indexed=False)
    newestSellOrder = db.DateProperty(default=None,  indexed=False)
    oldestSellOrder = db.DateProperty(default=None,  indexed=False)
    ordersBuy = db.IntegerProperty(default=0,  indexed=False)
    minBuyPrice = db.IntegerProperty(default=0,  indexed=False)
    maxBuyPrice = db.IntegerProperty(default=0,  indexed=False)
    averageBuyPrice = db.IntegerProperty(default=0,  indexed=False)
    medianBuyPrice = db.IntegerProperty(default=0,  indexed=False)
    volBuyRemaining = db.IntegerProperty(default=0,  indexed=False)
    volBuyEntered = db.IntegerProperty(default=0,  indexed=False)
    newestBuyOrder = db.DateProperty(default=None,  indexed=False)
    oldestBuyOrder = db.DateProperty(default=None,  indexed=False)
    date = db.DateProperty(required=True)
